/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Spider-Man
 * Date: 2025-04-09
 * Time: 22:58
 */
public class MainAll {
//无重复子字符串
    public int lengthOfLongestSubstring(String ss) {
        char[] s = ss.toCharArray(); //将字符串转换成字符存储在字符数组中
        int[] hash = new int[128]; //这个数组用来记录s中字符出现的次数
        //使用asii值表示字符, 与数据的下标对应.
        int left = 0, right = 0, n = ss.length();
        int ret = 0;
        while(right < n) {
            //进窗口
            hash[s[right]]++;
            while(hash[s[right]] > 1) {
                //只有在值>1就表示重复了,需要进行出窗口
                hash[s[left++]]--;//出窗口操作
            }
            right++;
            ret = Math.max(ret,right - left);
        }
        return ret;
    }
}
